﻿layui.define(['table', 'laytpl', 'jquery', 'form', 'index'], function (exports) {
    //初始化Layui模块
    var table = layui.table,
        index = layui.index,
        $ = layui.$,
        form = layui.form,
        laytpl = layui.laytpl;

    //初始化下拉列表
    index.jsonAjax('/Admin/PostManage/PostTypeList', function (data) {
        var $postType = $('#cmb_PostType');
        var postTypeHtml = $('#tpl_PostType').html();
        laytpl(postTypeHtml).render(data, function (html) {
            $postType.append(html);
            form.render('select');
        });
    });

    index.jsonAjax('/Admin/PostManage/PostStatusList', function (data) {
        var $postType = $('#chb_PostStatus');
        var postTypeHtml = $('#tpl_PostType').html();
        laytpl(postTypeHtml).render(data, function (html) {
            $postType.append(html);
            form.render('select');
        });
    });

    index.jsonAjax('/Admin/PostManage/PostSortList', function (data) {
        var $postType = $('#rdo_PostSort');
        var postTypeHtml = $('#tpl_PostType').html();
        laytpl(postTypeHtml).render(data, function (html) {
            $postType.append(html);
            form.render('select');
        });
    });

    //初始化表格内容
    table.render({
        elem: '#data_PostManage',
        url: '/Admin/PostManage/PostManageList',
        page: true,
        cols: [[
            { field: 'Title', title: '帖子标题', width: '20%', templet: '<div><a href="/Post/Detail?postId={{d.PostId}}">{{d.Title}}</a></div>' },
            { field: 'PostTypeStr', title: '帖子类型', width: '12%' },
            { field: 'PublishUserName', title: '发布者', width: '10%' },
            { field: 'PublishTimeStr', title: '发布时间', width: '10%' },
            { field: 'Status', title: '帖子状态', width: '15%', templet: '#tpl_PostStatus' },
            { field: 'Data', title: '数据', width: '10%', templet: '<div>{{d.ViewCount}}阅/{{d.ReplyCount}}回</div>' },
            { field: 'Operate', title: '操作', toolbar: '#tpl_Operate' }
        ]]
    });

    exports('postManage',null)
})